package tools

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"ruoyi-go/app/admin/model/tools"
	"ruoyi-go/utils"
	"strconv"
	"strings"
)

func GetListHandler(context *gin.Context) {
	pageNum, _ := strconv.Atoi(context.DefaultQuery("pageNum", "1"))
	pageSize, _ := strconv.Atoi(context.DefaultQuery("pageSize", "10"))
	var tableName = context.DefaultQuery("tableName", "")
	var tableComment = context.DefaultQuery("tableComment", "")

	var orderByColumn = context.DefaultQuery("orderByColumn", "")
	var isAsc = context.DefaultQuery("isAsc", "")

	var beginTime = context.DefaultQuery("params[beginTime]", "")
	var endTime = context.DefaultQuery("params[endTime]", "")

	var param = tools.SearchTableDataParam{
		PageNum:  pageNum,
		PageSize: pageSize,
		Other: tools.GenTable{
			TableNames:   tableName,
			TableComment: tableComment,
		},
		OrderByColumn: orderByColumn,
		IsAsc:         isAsc,
		Params: tools.Params{
			BeginTime: beginTime,
			EndTime:   endTime,
		},
	}
	context.JSON(http.StatusOK, tools.SelectGenList(param))
}

func GetGenById(context *gin.Context) {
	context.JSON(http.StatusOK, gin.H{
		"msg":  "操作成功",
		"code": http.StatusOK,
		"data": "",
	})
}

func GetDBListHandler(context *gin.Context) {
	pageNum, _ := strconv.Atoi(context.DefaultQuery("pageNum", "1"))
	pageSize, _ := strconv.Atoi(context.DefaultQuery("pageSize", "10"))
	var tableName = context.DefaultQuery("tableName", "")
	var tableComment = context.DefaultQuery("tableComment", "")

	var orderByColumn = context.DefaultQuery("orderByColumn", "")
	var isAsc = context.DefaultQuery("isAsc", "")

	var beginTime = context.DefaultQuery("params[beginTime]", "")
	var endTime = context.DefaultQuery("params[endTime]", "")

	var param = tools.SearchTableDataParam{
		PageNum:  pageNum,
		PageSize: pageSize,
		Other: tools.GenTable{
			TableNames:   tableName,
			TableComment: tableComment,
		},
		OrderByColumn: orderByColumn,
		IsAsc:         isAsc,
		Params: tools.Params{
			BeginTime: beginTime,
			EndTime:   endTime,
		},
	}
	context.JSON(http.StatusOK, tools.SelectGenDBList(param))
}

func ImportTableHandler(context *gin.Context) {
	var tables = context.DefaultQuery("tables", "")
	if tables == "" {
		context.JSON(http.StatusOK, gin.H{
			"msg":  "请选择要导入的表",
			"code": http.StatusInternalServerError,
		})
		return
	}
	arr := strings.Split(tables, ",")
	fmt.Print(arr)
}

func GetColumnGen(context *gin.Context) {
	context.JSON(http.StatusOK, gin.H{
		"msg":  "操作成功",
		"code": http.StatusOK,
		"data": "",
	})
}

func UpDataGen(context *gin.Context) {
	context.JSON(http.StatusOK, gin.H{
		"msg":  "操作成功",
		"code": http.StatusOK,
		"data": "",
	})
}

func DelectGenTable(context *gin.Context) {
	var tableIds = context.Param("tableIds")
	utils.Split(tableIds)
	context.JSON(http.StatusOK, gin.H{
		"msg":  "操作成功",
		"code": http.StatusOK,
		"data": "",
	})
}

func PreviewGen(context *gin.Context) {
	context.JSON(http.StatusOK, gin.H{
		"msg":  "操作成功",
		"code": http.StatusOK,
		"data": "",
	})
}

func DownloadGen(context *gin.Context) {
	context.JSON(http.StatusOK, gin.H{
		"msg":  "操作成功",
		"code": http.StatusOK,
		"data": "",
	})
}

func GetGenCode(context *gin.Context) {
	context.JSON(http.StatusOK, gin.H{
		"msg":  "操作成功",
		"code": http.StatusOK,
		"data": "",
	})
}

func GetsynchDb(context *gin.Context) {
	context.JSON(http.StatusOK, gin.H{
		"msg":  "操作成功",
		"code": http.StatusOK,
		"data": "",
	})
}

func GetBatchGenCode(context *gin.Context) {
	context.JSON(http.StatusOK, gin.H{
		"msg":  "操作成功",
		"code": http.StatusOK,
		"data": "",
	})
}
